// createStore 创建redux仓库 combineReducers 合并多个reducer apply运用 Middleware中间件
import {legacy_createStore as createStore,combineReducers,applyMiddleware,compose} from 'redux';
// 引入redux中间件 redux-thunk 解决action 异步提交问题
import ReduxThunk from 'redux-thunk';
import homeReducer from './reducer/homeReducer';
import cartReducer from './reducer/cartReducer';
// 合并reducer 获取状态时 state.homeReducer
let reducer = combineReducers({
    homeReducer,
    cartReducer
})
// 开启开发调试
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose
let store = createStore(reducer,composeEnhancers(applyMiddleware(ReduxThunk)));
export default store;

/* 
redux 设计三原则：
1. 状态是唯一。
2. state状态是只读的，更新需要返回新状态
3. reducer必须是纯函数
*/